define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'contents/yuyue/index/tp/' + Config.tp,
					info_url: 'contents/yuyue/info',
					tuikuan_url: 'contents/yuyue/tuikuan',
					fenpei_url: 'contents/yuyue/fenpei',
                    table: 'orders',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), sortable: true},
                        {field: 'order_sn', title: '勘察订单号'},
                        {field: 'kehu_truename', title: '客户姓名'},
						{field: 'kehu_mobile', title: '联系电话'},
                        {field: 'kehu_region', title: '户型区域'},
                        {field: 'mianji', title: '面积'},
                        {field: 'order_state_desc', title: '订单状态'},
                        {field: 'atime', title: '订单时间',},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter:function(value,row,index){
							var that=$.extend({},this);
							var table=$(that.table).clone(true);
							if(row.order_state<2){
								$(table).data('operate-fenpei',null);								
							}
							if(row.order_tp==1 || row.tuikuan==0){
								$(table).data('operate-tuikuan',null);
							}
							that.table=table;
							return Table.api.formatter.operate.call(that,value,row,index);
						}
						}
                    ]
                ]
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
			
        }
    };
    return Controller;
});